package com.ldl.distributelock.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ldl.distributelock.pojo.Stock;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface StockMapper extends BaseMapper<Stock> {

    @Update("update db_lock set count = count - #{count} where count >= #{count} and product_code = #{productCode}")
    int updateStock(@Param("productCode")String productCode,@Param("count")Integer count);

    @Select("select * from db_lock where product_code = #{productCode} for update")
    List<Stock> queryStock(@Param("productCode")String productCode);
}
